/*
 * @Author: CodeHare
 * @Date: 2023-09-19 18:46:23
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-16 18:03:46
 * @Description: EMS详情页面
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/model/device_model.dart';
import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/routers/router_path.dart';
import 'package:yt_devops/utils/enums.dart';
import '../../../utils/device_util.dart';
import 'ems_detail_controller.dart';
import '../../../components/detail_grid_widget.dart';

class EmsDetailPage extends GetWidget<EmsDetailController> {
  final DeviceModel? deviceModel;
  const EmsDetailPage({Key? key, required this.deviceModel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EmsDetailController>(initState: (state) {
      controller.deviceModel = deviceModel;
      controller.initData();
    }, builder: (_) {
      return Scaffold(
          appBar: AppBarWidget.withRightActions(
            controller.title,
            actions: <Widget>[
              if (!(deviceModel?.masterSlaveMode == MasterSlaveModeType.vice))
                InkWell(
                  onTap: () => Get.toNamed(
                    RouterPath.rectangleEmsRomoteControl,
                    arguments: {
                      'deviceId': controller.deviceId,
                      'productId': deviceModel?.productId
                    },
                  ),
                  child: Padding(
                    padding: EdgeInsets.only(right: 16.w),
                    child: Image.asset(
                      ImageAssets.iconRemoteControl,
                      width: 20.w,
                      height: 20.h,
                    ),
                  ),
                )
            ],
          ),
          body: GetBuilder<EmsDetailController>(
            builder: (controller) => ListView.builder(
              shrinkWrap: false,
              itemBuilder: (context, index) => DeviceUtil.blockContainer(
                DetailGridWidget(
                  title: controller.group[index].title,
                  items: controller.group[index].items,
                  dataSource: controller.dataSource,
                  isSingleRow: false,
                  isLightTtext:
                      controller.connectStatus != ConnectStatusType.on,
                  deviceModel: deviceModel,
                ),
              ),
              itemCount: controller.group.length,
            ),
          ));
    });
  }
}
